module.exports = (app) => {
  const { Schema, model, getModelName } = app.jax.mongoose
  const modelName = getModelName(__filename)

  const schema = new Schema({
    configName: String, // 配置文件名
    configType: String, // 配置标识
    state: Number, // 状态 0、待审核 1、上线 2、上线
    config: { type: Schema.Types.Mixed, default: {} },
    template: String,
    isPublic: { type: Boolean, default: false }, // 是否公开
    isSystem: { type: Boolean, default: false }, // 是否系统配置
  })

  schema.virtual('stateDesc').get(function () {
    const data = {
      0: '待选点',
      1: '上线',
      2: '下线',
    }

    return data[this.state] || '未知'
  })

  const Model = model(modelName, schema)

  return Model
}
